package com.web.manager;

import com.aliyun.oss.OSSClient;
import com.web.config.AliOssConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.InputStream;

/**
 *
 * @author FDjavaone
 * @date 2017/9/27
 */
@Service
public class FileUpLoadManager {
    @Autowired
    private AliOssConfiguration aliOssConfiguration;

    public String upload(InputStream is, String fileName) {
        // 创建OSSClient实例
        OSSClient ossClient = new OSSClient(aliOssConfiguration.getEnd_point(), aliOssConfiguration.getAccess_key_id(), aliOssConfiguration.getAccess_key_secret());
        ossClient.putObject(aliOssConfiguration.getBucket(), fileName, is);
        // 关闭client
        ossClient.shutdown();
        String src = aliOssConfiguration.getBucket() + "." + aliOssConfiguration.getEnd_point() + "/" + fileName;
        return src;
    }

}